package com.avcdata.national.adapter;

import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.avcdata.aoscustommade.R;
import com.avcdata.national.module.UserCompetingBrandInfo;
import com.avcdata.national.network.BaseLog;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * 关注品类适配器
 *
 * @author Administrator
 */
public class PersonalAttentionCategoryAdapter extends BaseAdapter {
    private Activity context;
    private List<UserCompetingBrandInfo.ReturnValueBean> list;

    public PersonalAttentionCategoryAdapter(Activity context, List<UserCompetingBrandInfo.ReturnValueBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View converView, ViewGroup arg2) {
        final ViewHolder holder;
        if (converView == null) {
            converView = LayoutInflater.from(context).inflate(R.layout.item_personal_attention_category, null);
            holder = new ViewHolder();
            holder.item_icon = (ImageView) converView.findViewById(R.id.item_icon);
            holder.categroy = (TextView) converView.findViewById(R.id.categroy);
            holder.brands = (TextView) converView.findViewById(R.id.brands);
            converView.setTag(holder);
        } else {
            holder = (ViewHolder) converView.getTag();
        }
        holder.categroy.setText(list.get(position).getCategory());
        ImageLoader.getInstance().displayImage(list.get(position).getUrl(), holder.item_icon);

        if(null == list.get(position).getCompetingBrands() || list.get(position).getCompetingBrands().size() == 0){
            holder.brands.setText("未添加竞品");
            holder.brands.setTextColor(context.getResources().getColor(R.color.red));
        }else{
            holder.brands.setTextColor(context.getResources().getColor(R.color.text_two));
            StringBuffer sb = new StringBuffer();
            sb.append("竞品：");
            for(String str : list.get(position).getCompetingBrands()){
                sb.append(str+"、");
            }
            sb.deleteCharAt(sb.length()-1);
            holder.brands.setText(sb.toString());
        }
        BaseLog.e("Adapter",list.get(position).getCategory());
        return converView;
    }

    class ViewHolder {
        private ImageView item_icon;
        private TextView categroy;
        private TextView brands;
    }

}
